package com.yunhai.web.controller.other;

import java.util.List;
import java.util.Arrays;

import com.yunhai.system.service.WorkJobService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yunhai.common.annotation.Log;
import com.yunhai.common.core.controller.BaseController;
import com.yunhai.common.core.domain.AjaxResult;
import com.yunhai.common.enums.BusinessType;
import com.yunhai.system.domain.WorkJob;
import com.yunhai.common.utils.poi.ExcelUtil;
import com.yunhai.common.core.page.TableDataInfo;

/**
 * 招聘信息Controller
 *
 * @author kim
 * @date 2021-01-16
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/other/workJob")
public class WorkJobController extends BaseController {

    private final WorkJobService workJobService;

    /**
     * 查询招聘信息列表
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkJob workJob) {
        startPage();
        List<WorkJob> list = workJobService.queryList(workJob);
        return getDataTable(list);
    }

    /**
     * 导出招聘信息列表
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:export')")
    @Log(title = "招聘信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkJob workJob) {
        List<WorkJob> list = workJobService.queryList(workJob);
        ExcelUtil<WorkJob> util = new ExcelUtil<WorkJob>(WorkJob.class);
        return util.exportExcel(list, "workJob");
    }

    /**
     * 获取招聘信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(workJobService.getById(id));
    }

    /**
     * 新增招聘信息
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:add')")
    @Log(title = "招聘信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkJob workJob) {
        return toAjax(workJobService.save(workJob) ? 1 : 0);
    }

    /**
     * 修改招聘信息
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:edit')")
    @Log(title = "招聘信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkJob workJob) {
        return toAjax(workJobService.updateById(workJob) ? 1 : 0);
    }

    /**
     * 删除招聘信息
     */
    @PreAuthorize("@ss.hasPermi('other:workJob:remove')")
    @Log(title = "招聘信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(workJobService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
